﻿using System;
using System.Collections;
using System.Windows;
using System.Windows.Controls;
using ContaPlanner.Models;

namespace ContaPlanner
{
    public partial class CuentasList
    {
        public event EventHandler CuentaChanged;

        public CuentasList()
        {
            InitializeComponent();
            CuentasListBox.SelectionChanged += CuentasListBox_SelectionChanged;
        }

        void CuentasListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (CuentaChanged != null) CuentaChanged(sender, e);
        }

        public IEnumerable Cuentas
        {
            get { return CuentasListBox.ItemsSource; }
            set { CuentasListBox.ItemsSource = value; }
        }

        public Cuenta SelectedCuenta
        {
            get { return CuentasListBox.SelectedItem as Cuenta; }
            set { CuentasListBox.SelectedItem = value; }
        }

        public void SelectFirst()
        {
            if (CuentasListBox.Items.Count == 0) return;
            CuentasListBox.SelectedIndex = 0;
        }

        private void Expander_OnCollapsed(object sender, RoutedEventArgs e)
        {
            Properties.Settings.Default.Expanded &= ~((Expander)sender).Tipo();
            Properties.Settings.Default.Save();
        }

        private void Expander_OnExpanded(object sender, RoutedEventArgs e)
        {
            Properties.Settings.Default.Expanded |= ((Expander)sender).Tipo();
            Properties.Settings.Default.Save();
        }
    }
}
